#include <iostream>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>

int main(void)
{
    int fd = open("/dev/remap_demo", O_RDWR);
    if (fd < 0) {
        std::cerr << "Failed to open /dev/remap_demo" << std::endl; 
        return 1;
    }

    int32_t shm_size = 4 << 20;

    char *buf = (char *)mmap(NULL, shm_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if (buf == MAP_FAILED) {
        std::cerr << "Failed to mmap /dev/remap_demo" << std::endl; 
        return 1;
    }

    int* ibuf = (int*)buf;
    for (int i = 0; i < shm_size / 4; i++) {
        ibuf[i] = i;
    }

    munmap(buf, shm_size);
    close(fd);

    return 0;
}